package com.coderman.infosys.auth.adapter.controller.authority;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.AuthorityConverter;
import com.coderman.infosys.auth.app.convert.AuthorityConvert;
import com.coderman.infosys.auth.domain.gataway.AuthorityQueryGataWay;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coderman.infosys.auth.adapter.vo.authority.AuthorityVO;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.coderman.infosys.auth.domain.factory.AuthorityFactory;
import com.coderman.infosys.auth.domain.bo.authority.AuthorityBO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class AuthorityQueryController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(AuthorityQueryController.class);

	@Autowired
	private AuthorityFactory authorityFactory;

	@Autowired
	public AuthorityQueryGataWay authorityQueryGataWay;


	/**
	 *
	 * @Description 分页获取权限信息
	 * @return PageVO<AuthorityVO>
	 */
	@RequestMapping(value = "/authority/pagelist")
	public ResultDataDto<PageVO> getPageList(PageVO pageVO){
		List<AuthorityBO> authorityBOList = authorityQueryGataWay.getPageList(pageVO.convertToBO());
		pageVO.setItems(AuthorityConverter.INSTANCE.boList2voList(authorityBOList));
		return ResultDataDto.success(pageVO);
	}

	/**
	 *
	 * @Description 获取权限信息
	 * @param authorityCode
	 * @return AuthorityVO
	 */
	@RequestMapping(value = "/authority/getbycode")
	public ResultDataDto<AuthorityVO> getByCode(@RequestParam(value = "authorityCode", required = true) String authorityCode){
        AuthorityBO authorityBO = authorityFactory.buildAuthorityByCode(authorityCode);
		return ResultDataDto.success(AuthorityConverter.INSTANCE.bo2VO(authorityBO));
	}

}
